package com.kuang.util;

import lombok.Data;

import java.io.Serializable;

/**
 * 用于封装返回给前端的信息
 * */
@Data
public class ResultModel<T> implements Serializable {
    // 状态码
    private int code;
    // 消息
    private String message;
    // 数据
    private T data;

    private static ResultModel resultModel = new ResultModel();

    public static ResultModel success(){
        resultModel.setCode(200);
        resultModel.setMessage("请求成功");
        resultModel.setData(null);
        return resultModel;
    }

    public static ResultModel success(String message){
        resultModel.setCode(200);
        resultModel.setMessage(message);
        resultModel.setData(null);
        return resultModel;
    }

    public static ResultModel success(Object data){
        resultModel.setCode(200);
        resultModel.setMessage("请求成功");
        resultModel.setData(data);
        return resultModel;
    }

    public static ResultModel success(String message,Object data){
        resultModel.setCode(200);
        resultModel.setMessage(message);
        resultModel.setData(data);
        return resultModel;
    }

    public static ResultModel error(){
        resultModel.setCode(500);
        resultModel.setMessage("请求失败");
        resultModel.setData(null);
        return resultModel;
    }

    public static ResultModel error(int code,String message){
        resultModel.setCode(code);
        resultModel.setMessage(message);
        resultModel.setData(null);
        return resultModel;
    }
}
